{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### CPU和内存"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Number of CPU cores (logical): 8\n",
      "Number of CPU cores (physical): 8\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "\n",
    "# Get the number of logical CPU cores\n",
    "num_cores = os.cpu_count()\n",
    "print(f\"Number of CPU cores (logical): {num_cores}\")\n",
    "\n",
    "# To get the number of physical CPU cores (only available on some platforms)\n",
    "import psutil\n",
    "num_physical_cores = psutil.cpu_count(logical=False)\n",
    "print(f\"Number of CPU cores (physical): {num_physical_cores}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Total RAM: 30.60 GB\n"
     ]
    }
   ],
   "source": [
    "import psutil\n",
    "\n",
    "# Get total memory\n",
    "total_memory = psutil.virtual_memory().total\n",
    "print(f\"Total RAM: {total_memory / (1024**3):.2f} GB\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 磁盘"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Total Disk Space: 48.91 GB\n",
      "Used Space: 14.52 GB\n",
      "Free Space: 31.88 GB\n",
      "Percentage Used: 31.3%\n"
     ]
    }
   ],
   "source": [
    "import psutil\n",
    "\n",
    "# Get disk usage for the root partition (or any specific path)\n",
    "disk = psutil.disk_usage('/')\n",
    "\n",
    "print(f\"Total Disk Space: {disk.total / (1024**3):.2f} GB\")\n",
    "print(f\"Used Space: {disk.used / (1024**3):.2f} GB\")\n",
    "print(f\"Free Space: {disk.free / (1024**3):.2f} GB\")\n",
    "print(f\"Percentage Used: {disk.percent}%\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### GPU"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "index, name, memory.total [MiB], memory.used [MiB], memory.free [MiB], temperature.gpu\n",
      "0, Tesla T4, 15360 MiB, 2 MiB, 14926 MiB, 33\n",
      "\n"
     ]
    }
   ],
   "source": [
    "import subprocess\n",
    "\n",
    "result = subprocess.run(['nvidia-smi', '--query-gpu=index,name,memory.total,memory.used,memory.free,temperature.gpu', '--format=csv'],\n",
    "                        stdout=subprocess.PIPE, text=True)\n",
    "print(result.stdout)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python (base)",
   "language": "python",
   "name": "base"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.11"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
